﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RED_NET_Core.DAL;
using RED_NET_Core.Entity;

namespace RED_NET_Core.BLL
{
    public class LoginBLL
    {
        Login_DAL ndal;

        #region [构造函数]

        /// <summary>
        /// 构造函数
        /// </summary>
        public LoginBLL()
        {
            ndal = new Login_DAL();
        }

        #endregion

        #region [根据用户名密码登录]

        public int GetUserId(string userName, string userPassword)
        {
            return ndal.IsValidUser(userName, userPassword);
        }

        #endregion

        #region [获取登录用户的信息]

        public Users GetMessageOfUser(int uid)
        {
            return ndal.GetMessageOfUser(uid);
        }

        #endregion

        #region[修改最后登录时间]

        public bool UpdateLoginTimeOfUser(int uid)
        {
            return ndal.UpdateLoginTimeOfUser(uid);
        }

        #endregion

        #region [发表新博文后修改拥有的博文数]

        public bool UpdateBlogNumOfUser(int uid, int blogNum)
        {
            return ndal.UpdateBlogNumOfUser(uid, blogNum);
        }

        #endregion

        #region [修改密码]

        public bool UpdatePasswordOfUser(int uid, string userName, string oldPassword, string newPassword)
        {
            return ndal.UpdatePasswordOfUser(uid, userName, oldPassword, newPassword);
        }

        #endregion

        #region [修改昵称]

        public bool UpdateNickNameOfUser(int uid, string newNickName)
        {
            return ndal.UpdateNickNameOfUser(uid, newNickName);
        }

        #endregion

        #region [获取关注者信息]

        /// <summary>
        /// 获取关注者的信息（UId和UserName）
        /// </summary>
        /// <param name="nUId">用户Id</param>
        /// <returns>返回含有UIdheUserName的DataTable</returns>
        public DataTable GetMyAttentionInfo(int nUId, int nNum)
        {

            return ndal.GetMyAttentionInfo(nUId, nNum);
        }
        #endregion
        #region[删除关注信息]
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_Id">UserRel中的记录id</param>
        public void DeleteUserRel(int nId)
        {
            ndal.DeleteUserRel(nId);
        }
        #endregion
        #region[获取院级用户]
        /// <summary>
        /// 获取院级用户
        /// </summary>
        /// <returns>返回UId和NickName</returns>
        public DataTable GetCollegeUser()
        {
            return ndal.GetCollegeUser();
        }
        #endregion

        #region[获取班级用户]
        /// <summary>
        /// 获取班级用户
        /// </summary>
        /// <returns>返回UId和NickName</returns>
        public DataTable GetClassUser(int nCollegeId)
        {

            return ndal.GetClassUser(nCollegeId);
        }
        #endregion
        #region[判断是否存在关注关系]
        /// <summary>
        /// 判断是否存在关注关系
        /// </summary>
        /// <param name="nUId1"></param>
        /// <param name="nUId2">被关注的用户</param>
        /// <returns>若nUId1关注了nUId2则返回1，否则返回0</returns>
        public int JudgeUserRel(int nUId1, int nUId2)
        {
            return ndal.JudgeUserRel(nUId1, nUId2);
        }
        #endregion
        #region[添加关注]
        /// <summary>
        /// 添加关注
        /// </summary>
        /// <param name="nUId"></param>
        /// <param name="nAttentionTd"></param>
        /// <returns></returns>
        public int AddAttention(int nUId, int nAttentionTd)
        {
          return   ndal.AddAttention(nUId, nAttentionTd);
        }
#endregion
        #region[添加访问记录]
        /// <summary>
        /// 添加访问记录
        /// </summary>
        /// <param name="nId"></param>
        /// <param name="nVisitId"></param>
        public void AddVisitInfo(int nId, int nVisitId)
        {
            ndal.AddVisitInfo(nId, nVisitId);

        }
        #endregion
        #region[获得最近访客信息]
        /// <summary>
        /// 获得最近访客信息
        /// </summary>
        /// <param name="nUId"></param>
        /// <returns></returns>
        public DataTable GetLatestVisitor(int nUId)
        {
            return ndal.GetLatestVisitor(nUId);
        }
        #endregion

        #region[获取对应用户的权限值]

        public int GetRight(int Uid)
        {
            return ndal.GetRight(Uid);
        }

        #endregion

        #region[获取对应用户的学院id]
        public int GetCollegeIdOfUser(int Uid)
        {
            ndal = new Login_DAL();
            return ndal.GetcollegeId(Uid);
        }
        #endregion
        #region[判断用户是否合法]
        public bool IsValidUser(int uid, string pass)
        {
            string _realPass = ndal.GetPass(uid);
            if (_realPass == pass)
            {
                return true;
            }
            else
                return false;
        }
        #endregion
    }
        
}